<?php 
/**
 * 商品属性模型
 */
class Goods_AttrModel extends Model{
    public $table = 'goods_attr';
    
    public $validate = array();
    
	public function addData($gid){
		//插入商品属性表
		//插入属性
		foreach ($_POST['attr'] as $taid => $value) {
			//如果不为空才插入
			if($value){
				$data = array(
					'gtvalue' => $value,
					'attribute_atid' => $taid,
					//因为没有添加商品，所以模拟商品id为1
					'goods_gid' => $gid
				);
				$this->add($data);
			}
		}
		//插入规格
		//判断是否为空------>用户有可能不填
		$spec = isset($_POST['spec']) ? $_POST['spec'] : array();
		foreach ($spec as $taid => $v) {
			//这个地方为什么要循环，看打印的post
			foreach ($v['value'] as $key => $value) {
				$data = array(
					'gtvalue' => $value,
					'added' => $v['price'][$key],
					'attribute_atid' => $taid,
					//因为没有添加商品，所以模拟商品id为1
					'goods_gid' => $gid
				);
				$this->add($data);
			}
			
		}
		return TRUE;
	}
	
	public function editData($gid){
		//先删除
		$this->where("goods_gid={$gid}")->delete();
		//插入商品属性表
		//插入属性
		foreach ($_POST['attr'] as $taid => $value) {
			//如果不为空才插入
			if($value){
				$data = array(
					'gtvalue' => $value,
					'attribute_atid' => $taid,
					//因为没有添加商品，所以模拟商品id为1
					'goods_gid' => $gid
				);
				$this->add($data);
			}
		}
		//插入规格
		//判断是否为空------>用户有可能不填
		$spec = isset($_POST['spec']) ? $_POST['spec'] : array();
		foreach ($spec as $taid => $v) {
			//这个地方为什么要循环，看打印的post
			foreach ($v['value'] as $key => $value) {
				$data = array(
					'gtvalue' => $value,
					'added' => $v['price'][$key],
					'attribute_atid' => $taid,
					//因为没有添加商品，所以模拟商品id为1
					'goods_gid' => $gid
				);
				$this->add($data);
			}
			
		}
		return TRUE;
	}
	
 }
 
 
 
 
 
 
 
 
 
 
 


 ?>